//
//  MeViewController.m
//  FangXinLang
//
//  Created by AJY on 16/9/18.
//  Copyright © 2016年 AJY. All rights reserved.
//

#import "MeViewController.h"
#import "LoginRedTableViewCell.h"
#import "CellTableViewCell.h"
#import "LoginViewController.h"
#import "SetUpViewController.h"
#import "Abtn.h"

#import "SearchViewController.h"//搜索.调试用的,后期删了

@interface MeViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView * tableView;

@property (nonatomic,strong) NSMutableArray * arrMP;//存放三个图标的数组(夜间模式~更多设置)

@property (nonatomic,strong) NSMutableArray * arrML;//存放三个名字的数组(夜间模式~更多设置)

@property (nonatomic,strong) NSMutableArray * arrMP1;//存放三个图标的数组(检查更新~关于)

@property (nonatomic,strong) NSMutableArray * arrML1;//存放三个名字的数组(检查更新~关于)

@end

@implementation MeViewController
#pragma mark 加载时调用
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView=[[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStyleGrouped];
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:self.tableView];
    self.tableView.contentInset=UIEdgeInsetsMake(-50, 0, 0, 0);
    self.tableView.bounces = NO;
}
#pragma mark 返回多少组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
#pragma mark 返回多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }else if (section == 1){
        return 3;
    }else{
        return 3;
    }
}
#pragma mark 返回cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * temp = nil;
    if (indexPath.section == 0) {
        static NSString * ID = @"LoginRed";
        LoginRedTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (cell == nil) {
            cell = [LoginRedTableViewCell loadLoginRedTableViewCell];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell.ShouCang addTarget:self action:@selector(AlertController) forControlEvents:UIControlEventTouchUpInside];
        [cell.PingLun addTarget:self action:@selector(AlertController) forControlEvents:UIControlEventTouchUpInside];
        [cell.WoDeKaBao addTarget:self action:@selector(AlertController) forControlEvents:UIControlEventTouchUpInside];
        [cell.JiFenShangCheng addTarget:self action:@selector(AlertController) forControlEvents:UIControlEventTouchUpInside];
        temp = cell;
    }else if (indexPath.section == 1){
        static NSString * ID = @"Cell";
        CellTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (cell == nil) {
            cell = [CellTableViewCell loadCellTableViewCell];
        }
        [self addPL];
        cell.imgView.image = self.arrMP[indexPath.row];
        cell.Name.text = self.arrML[indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        temp = cell;
    }else if (indexPath.section == 2){
        static NSString * ID = @"Cell";
        CellTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (cell == nil) {
            cell = [CellTableViewCell loadCellTableViewCell];
        }
        [self addPL1];
        cell.imgView.image = self.arrMP1[indexPath.row];
        cell.Name.text = self.arrML1[indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        temp = cell;
    }
    return temp;
}
#pragma mark 定义行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 300;
    }else if (indexPath.section == 1) {
        return 55;
    }else {
        return 55;
    }
}
#pragma mark tableview下面的第二组里面cell的图标和标题
-(void)addPL{
    self.arrMP = [NSMutableArray array];
    self.arrML = [NSMutableArray array];
    for (int i=1; i<=3; i++){
        if (i==1) {
            UIImage * img = [UIImage imageNamed:[NSString stringWithFormat:@"settableview_changenight_normal@3x"]];
            [self.arrMP addObject:img];
            NSString * str = @"夜间模式";
            [self.arrML addObject:str];
        }else if (i == 2){
            UIImage * img = [UIImage imageNamed:[NSString stringWithFormat:@"settableview_offlinedownload_normal"]];
            [self.arrMP addObject:img];
            NSString * str = @"离线下载";
            [self.arrML addObject:str];
        }else {
            UIImage * img = [UIImage imageNamed:[NSString stringWithFormat:@"settableview_moresetting_normal@3x"]];
            [self.arrMP addObject:img];
            NSString * str = @"更多设置";
            [self.arrML addObject:str];
        }
    }
}
#pragma mark tableview下面的第三组里面cell的图标和标题
-(void)addPL1{
    self.arrMP1 = [NSMutableArray array];
    self.arrML1 = [NSMutableArray array];
    for (int i=1; i<=3; i++){
        if (i == 1){
            UIImage * img = [UIImage imageNamed:[NSString stringWithFormat:@"navigationbar_refresh_icon"]];
            [self.arrMP1 addObject:img];
            NSString * str = @"检查更新";
            [self.arrML1 addObject:str];
        }else if (i == 2){
            UIImage * img = [UIImage imageNamed:[NSString stringWithFormat:@"settableview_feedback_normal@3x"]];
            [self.arrMP1 addObject:img];
            NSString * str = @"反馈";
            [self.arrML1 addObject:str];
        }else {
            UIImage * img = [UIImage imageNamed:[NSString stringWithFormat:@"settableview_about_normal@3x"]];
            [self.arrMP1 addObject:img];
            NSString * str = @"关于";
            [self.arrML1 addObject:str];
        }
    }
}
#pragma mark tableviewCell的监听事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //判断是不是第一组的第一行
    if (indexPath.section == 0 && indexPath.row == 0) {
        LoginViewController * login = [[LoginViewController alloc]init];
        login.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:login animated:YES];
    }else if (indexPath.section == 1 && indexPath.row == 2) {
        SetUpViewController * login = [[SetUpViewController alloc]init];
        login.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:login animated:YES];
    }else if (indexPath.section == 2 && indexPath.row == 1){
        SearchViewController * login = [[SearchViewController alloc]init];
        login.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:login animated:YES];
    }
}
#pragma mark 提示框
-(void)AlertController{
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"登录新浪微博后继续操作" message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * actionL = [UIAlertAction actionWithTitle:@"登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        LoginViewController * login = [[LoginViewController alloc]init];
        login.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:login animated:YES];
    }];
    UIAlertAction * actionR = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
    [alert addAction:actionL];
    [alert addAction:actionR];
    [self presentViewController:alert animated:YES completion:nil];
}
@end
